home *** CD-ROM | disk | FTP | other *** search
- ;void input_line(col,row,color,max_len,char_case,return_string);
- ; unsigned short col,row,color,max_len;
- ; char char_case,*return_string;
-
- EXTRN _memory_model:byte
- EXTRN _beep_on:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _input_line
- _input_line proc near
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- mov _error_code,0 ;assume that no error
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- les si,dword ptr[bp+14] ;get ptr to return string
- jmp short L00 ;
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov si,[bp+14] ;
- L00: mov byte ptr es:[si],0 ;null string in case an error
- mov dl,[bp+4] ;col to DL
- dec dl ;count from 0
- cmp dl,79 ;in range?
- jna B1 ;jump ahead if so
- A1: inc _error_code ;1 = parameter out of range
- jmp P1 ;else quit
- B1: mov dh,[bp+6] ;row to DH
- dec dh ;count from 0
- cmp dh,24 ;in range?
- ja A1 ;quit if not
- mov bl,[bp+8] ;attribute to BL
- sub bh,bh ;page 0
- mov al,[bp+10] ;max string length to AL
- or al,al ;test for zero
- jz A1 ;quit if zero
- mov ah,[bp+12] ;character case to AH
- mov di,ax ;store both in DI
- mov ah,2 ;function to set cursor
- int 10h ;set the cursor
- mov bp,si ;keep BP pointing to descriptor
- sub al,al ;initial string length
- mov es:[si],al ;set the descriptor
- C1: inc si ;forward string pointer
- D1: mov cx,1 ;num chars to write
- sub ah,ah ;func to read keystroke
- int 16h ;wait for keystroke
- cmp al,0 ;test for extended code
- je D1 ;ignore if extended
- cmp al,13 ;test for carriage return
- jne E1 ;jump ahead if not CR
- jmp P1 ;else quit routine
- E1: cmp al,9 ;test for tab
- je D1 ;ignore if tab
- cmp al,27 ;test for Escape
- jne G1 ;jump ahead if not
- mov cl,es:[bp] ;string length to CX
- or cl,cl ;test for null string
- je D1 ;ignore keystroke if null
- mov es:[bp],ch ;zero out strg length
- sub si,si ;clear string pointer
- F1: dec dl ;dec column position
- mov ah,2 ;function to set cursor
- int 10h ;reset the cursor
- mov al,32 ;erase with spc character
- push cx ;save strg len counter
- mov cx,1 ;number chars to write
- mov ah,9 ;function to write char
- int 10h ;erase a char
- pop cx ;restore counter
- loop F1 ;go erase next char
- jmp short C1 ;go get next keystroke
- G1: cmp al,8 ;test for backspace
- jne H1 ;jump ahead if not bkspc
- cmp es:[bp],ch ;start of string?
- je I1 ;go beep, get next key
- sub es:[bp],cl ;dec string descriptor
- dec si ;dec string pointer
- dec dl ;dec cursor col
- mov ah,2 ;function to set cursor
- int 10h ;reset cursor
- mov al,32 ;erase with space char
- mov ah,9 ;function to write char
- int 10h ;erase a char
- jmp short D1 ;get get next char
- H1: xchg di,cx ;fetch MaxLen
- cmp es:[bp],cl ;comp to strg descriptor
- xchg di,cx ;restore CX
- jne K1 ;jump if string not full
- I1: push dx ;save cursor setting
- mov ah,2 ;DOS func to write char
- mov dl,7 ;bell character
- cmp _beep_on,0 ;check whether to beep
- je J1 ;jump if shouldn't
- int 21h ;beep!
- J1: pop dx ;restore cursor setting
- jmp short D1 ;go get next keystroke
- K1: xchg cx,di ;move case type to CH
- cmp ch,'u' ;upper case?
- je L1 ;jump if so
- cmp ch,'U' ;upper case?
- jne M1 ;jump ahead if not
- L1: cmp al,'a' ;below 'a'?
- jb O1 ;move on if out of range
- cmp al,'z' ;above 'z'?
- ja O1 ;move on if out of range
- sub al,32 ;convert to upper case
- jmp short O1 ;go write it
- M1: cmp ch,'l' ;lower case?
- je N1 ;jump if so
- cmp ch,'L' ;lower case?
- jne O1 ;no adjustment if not
- N1: cmp al,'A' ;below 'A'?
- jb O1 ;move on if out of range
- cmp al,'Z' ;above 'Z'?
- ja O1 ;move on if out of range
- add al,32 ;convert to upper case
- O1: xchg cx,di ;restore CX count
- mov es:[si],al ;set keystroke for return
- add es:[bp],cl ;increment the descriptor
- mov ah,9 ;function to write char
- int 10h ;write the char
- inc dl ;forward cursor col
- mov ah,2 ;function to set cursor
- int 10h ;reset the cursor
- jmp C1 ;go get next character
- P1: sub cx,cx ;change to C string
- mov cl,es:[bp] ;get string length
- jcxz R1 ;quit if null
- Q1: inc bp ;
- mov al,es:[bp] ;
- mov es:[bp-1],al ;
- loop Q1 ;
- mov byte ptr es:[bp],0 ;null terminator
- R1: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _input_line ENDP
- _TEXT ENDS
- END